# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: jaewon, inkyu

from absl import app, flags
from tornado.ioloop import IOLoop

from coin.util.log_watcher.log_watcher import LogWatcher
from coin.util.log_watcher.readers import AsyncLogTailReader
from coin.util.log_watcher.log_stdout_printer import print_log


class StderrLogWatcher(LogWatcher):
  _TailReader = AsyncLogTailReader
  _recursive = False


def main(argv=None):
  argv = flags.FLAGS(argv)

  try:
    ioloop = IOLoop()
    watcher = StderrLogWatcher(target_dir=argv[1], log_callback=print_log)
    watcher.start(ioloop)
    ioloop.start()
    watcher.stop()
    return 0
  except (KeyboardInterrupt, SystemExit):
    print
    return 1


if __name__ == "__main__":
  app.run(main)
